package base.proxy;

import exam.service.UserService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class UserServiceJDKProxy {

    public UserService createUserServiceJDKProxy(final UserService userService) {
        ClassLoader cl = UserService.class.getClassLoader();
        Class[] classes = userService.getClass().getInterfaces();
        InvocationHandler ih = new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                Object ret = method.invoke(userService, args);
                System.out.println("刮大白");
                System.out.println("贴壁纸");
                return ret;
            }
        };
        UserService service = (UserService) Proxy.newProxyInstance(cl,classes,ih);
        return service;
    }

}
